$(function () {
	//回显
	echoProporInfo();
	
    //是否验证成功
    $('#serviceForm').validationEngine('attach', {
        validationEventTrigger : 'blur',	//当提交的时候验证是否合法
        promptPosition: 'inline',
        scroll: false,
        focusFirstField : true,
        onValidationComplete : function (form, valid) {
    		if (valid){
    			updateProporInfo(form.context.id);
            }
        }
    });
    
});

//点击编辑回显数据
function echoProporInfo(){
    $.ajax({
        url: "../bill/getBillServeVehicleInfo.htm",
        cache: false,
        type: "get",
        dataType: "json",
        beforeSend:function(){var index = layer.load(1, {shade: [0.8,'#ddd']});},
        complete:function(){var index = layer.closeAll("loading");},
        success: function (result) {
            if (result.status == 0) {
                var data = result.data;
        		var billServe = data.billServe;
        		var billVehicle = data.billVehicle;
        			$("#serviceForm").formatForm(billServe);
    				$("#driverForm").formatForm(billVehicle);

            }
        }
    });
}

//关闭窗口
function closeForm() {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

//计费规则信息
function updateProporInfo(fromContext) {
    $.ajax({
        url: "../bill/modifyBillServeVehicleInfo.htm",
        cache: false,
        type: "post",
        dataType: "json",
        data: $("#" + fromContext).serialize(),
        success: function (result) {
            if (result.status == 0) {
            	layer.msg(result.message, {icon: 1});
            } else {
                layer.msg(result.message, {icon: 2});
            }
        }
    });
}
